from __future__ import annotations

from dataclasses import dataclass
from typing import List, Tuple


@dataclass
class MassPoint:
    x: float
    y: float
    z: float
    mass_kg: float


@dataclass
class MassCentroid:
    total_mass_kg: float
    centroid: Tuple[float, float, float]
    note: str


def compute_panel_mass_centroid(points: List[MassPoint]) -> MassCentroid:
    """塔片重量与重心计算：按离散构件质量点叠加。"""

    if not points:
        return MassCentroid(0.0, (0.0, 0.0, 0.0), "空输入")
    mt = sum(p.mass_kg for p in points)
    cx = sum(p.x * p.mass_kg for p in points) / max(1e-9, mt)
    cy = sum(p.y * p.mass_kg for p in points) / max(1e-9, mt)
    cz = sum(p.z * p.mass_kg for p in points) / max(1e-9, mt)
    return MassCentroid(total_mass_kg=mt, centroid=(cx, cy, cz), note="离散求和")


